package parallel;

import consumer.Consumer;
import producer.Producer;
import queue.Queue1;



/**
 * @author Xu,
 * @data 2020/12/20，
 * @time 10:11
 */
public class Parallel {
    public static void main(String[] args) throws InterruptedException {
        long start = System.currentTimeMillis();
        Queue1 queue = new Queue1();
        Producer producer = new Producer(queue, 1000000);
        Thread t1 = new Thread(producer);
        Consumer consumer1 = new Consumer(queue, 500000);
        Consumer consumer2 = new Consumer(queue, 500000);
        Thread t2 = new Thread(consumer1);
        Thread t3 = new Thread(consumer2);
        t1.start();
        t2.start();
        t3.start();
        t1.join();
        t2.join();
        t3.join();
        System.out.println(producer.getCount());
        System.out.println(consumer1.getCount());
        System.out.println(consumer2.getCount());
        long end = System.currentTimeMillis();
        System.out.println("runtime: " + (end-start)/1000.0 + "s");
    }
}
